using System;

using Atomic.Libraries;
using Atomic.Libraries.Mathematics;

namespace Atomic.Structures
{
	/// <summary>
	/// Represents a displaced atom in the frozen phonon model.
	/// </summary>
	[Serializable]
	public class DisplacedAtom : Atom
	{
		[NonSerialized] private int hashCode;

		public DisplacedAtom(Atom baseAtom, SpaceVector displacement)
		{
			BaseAtom = baseAtom;
			Displacement = displacement;
		}

		public override bool Equals(Atom other)
		{
			return Equals(other as DisplacedAtom);
		}

		public bool Equals(DisplacedAtom other)
		{
			if (object.ReferenceEquals(other, null))
			{
				return false;
			}

			return EqualityHelper.Equals(this, other, new object[] { BaseAtom, Displacement }, new object[] { other.BaseAtom, other.Displacement }, hashCode, other.hashCode);
		}

		public override int GetHashCode()
		{
			if (hashCode == 0)
			{
				hashCode = EqualityHelper.HashCode(new object[] { BaseAtom, Displacement });
			}

			return hashCode;
		}

		public Atom BaseAtom
		{
			get;
			private set;
		}

		public SpaceVector Displacement
		{
			get;
			private set;
		}

		public override int Number
		{
			get
			{
				return BaseAtom.Number;
			}
		}

		public override string Symbol
		{
			get
			{
				return BaseAtom.Symbol;
			}
		}

		public override double Mass
		{
			get
			{
				return BaseAtom.Mass;
			}
		}

		public override string ElectronConfiguration
		{
			get
			{
				return BaseAtom.ElectronConfiguration;
			}
		}
	}
}
